c# datetime to timestamp

48

convert timestamp to datetime c# code -

public static DateTime UnixTimeStampToDateTime( double unixTimeStamp )
{
    // Unix timestamp is seconds past epoch
    System.DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
    dtDateTime = dtDateTime.AddSeconds( unixTimeStamp ).ToLocalTime();
    return dtDateTime;
}

c# datetime now timestamp -

var Timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();

c# datetime to timestamp -

DateTimeOffset.UtcNow.ToUnixTimeSeconds()

Comments

Submit
0 Comments